using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Markup;
using Common;

namespace MainView.MainControls
{
	public partial class QuickExperimentControl : UserControl, IComponentConnector
	{
		public static readonly DependencyProperty QuickDataProperty = DependencyProperty.Register("QuickData", typeof(QuickExperimentData), typeof(QuickExperimentControl), new PropertyMetadata(null));

		public static readonly RoutedEvent OnQuickExperimentConrtolChangedRoutedEvent = EventManager.RegisterRoutedEvent("OnQuickExperimentConrtolChangedRoutedEvent", RoutingStrategy.Bubble, typeof(EventHandler<RoutedEventArgs>), typeof(QuickExperimentControl));

		public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register("IsSelected", typeof(bool), typeof(QuickExperimentControl), new PropertyMetadata(false));

		public static readonly DependencyProperty IsShowCheckBoxProperty = DependencyProperty.Register("IsShowCheckBox", typeof(bool), typeof(QuickExperimentControl), new PropertyMetadata(false));

		public QuickExperimentData QuickData
		{
			get
			{
				return (QuickExperimentData)GetValue(QuickDataProperty);
			}
			set
			{
				SetValue(QuickDataProperty, value);
			}
		}

		public bool IsSelected
		{
			get
			{
				return (bool)GetValue(IsSelectedProperty);
			}
			set
			{
				SetValue(IsSelectedProperty, value);
			}
		}

		public bool IsShowCheckBox
		{
			get
			{
				return (bool)GetValue(IsShowCheckBoxProperty);
			}
			set
			{
				SetValue(IsShowCheckBoxProperty, value);
			}
		}

		public event RoutedEventHandler ManageChanged
		{
			add
			{
				AddHandler(OnQuickExperimentConrtolChangedRoutedEvent, value);
			}
			remove
			{
				RemoveHandler(OnQuickExperimentConrtolChangedRoutedEvent, value);
			}
		}

		public QuickExperimentControl()
		{
			InitializeComponent();
		}

		private void CheckBox_Click(object sender, RoutedEventArgs e)
		{
			if (e.Source is CheckBox)
			{
				CheckBox checkBox = e.Source as CheckBox;
				if (checkBox.DataContext is QuickExperimentData)
				{
					RaiseEvent(new RoutedEventArgs
					{
						RoutedEvent = OnQuickExperimentConrtolChangedRoutedEvent
					});
				}
			}
		}
	}
}
